package com.erpanderp.wam.usm.model.service.user;

import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;

import com.erpanderp.wam.usm.model.entity.user.PassportAndPANDetails;
import com.erpanderp.wam.util.HibernateUtil;

public class PassportAndPANDAO {
	
	 public PassportAndPANDetails getPassportAndPANDetails(Long newJoineeId)  {
		 PassportAndPANDetails passportAndPANDetail = null;
				try {
					Session session = HibernateUtil.getSessionFactory().getCurrentSession();
					session.beginTransaction();
					session.setFlushMode(FlushMode.COMMIT);
					Query query = session.createQuery("from PassportAndPANDetails pp where pp.newjoinee.newJoineeId= :newJoineeId").setLong(
							"newJoineeId", newJoineeId);
					
					query.setCacheable(false);
					List<PassportAndPANDetails> tempList = query.list();
					session.getTransaction().commit();
					if(tempList != null && tempList.size()>0){
						System.out.println("NOT NULL");
						passportAndPANDetail = tempList.get(0);
						return passportAndPANDetail;
					}else{
						System.out.println("NULL");
						return null;
					}
				} catch (Exception e) {
					e.printStackTrace();
					return null;
				}		
			}

}
